
import gov.nih.mipav.view.ViewUserInterface;

import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList;

import javax.swing.JFileChooser;

public class JSHTMLCreator {

	public void create(ArrayList<Region> regions) {
		String html = "<html><head></head><body>";
		html += "<table border=1>";
		html += "<tr>";
		html += "<td> Region Name </td>";
		html += "<td> Media </td>";
		html += "<td> Varianza </td>";
		html += "<td> Curtosis </td>";
		html += "</tr>";

		for (int i = 0; i < regions.size(); i++) {
			html += "<tr>";
			html += "<td>" + regions.get(i).getName() + "</td>";
			html += "<td>" + regions.get(i).getMedia() + "</td>";
			html += "<td>" + regions.get(i).getVariance() + "</td>";
			html += "<td>" + regions.get(i).getCurtosis() + "</td>";
			html += "</tr>";
		}
		html += "</table>";
		html += "</body></html>";

		JFileChooser fc = new JFileChooser();

		// Show save dialog; this method does not return until the dialog is
		// closed
		fc.showSaveDialog(ViewUserInterface.getReference().getMainFrame());
		File myFile = fc.getSelectedFile();
		FileOutputStream fop;
		try {
			fop = new FileOutputStream(myFile);

			if (myFile.exists()) {
				fop.write(html.getBytes());

				fop.flush();
				fop.close();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
}
